<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/10/22
 * Time: 16:05
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\model\mysql;

use think\Model;

class Base extends Model
{
    protected $autoWriteTimestamp = true;

    /**
     * @param int $id
     * @param array $data
     * @return bool
     */
    public function updateByData(int $id = 0, array $data = [])
    {
        if ($id == 0) {
            return false;
        }
        return $this->where('id', $id)
            ->save($data);
    }

    /**
     * 添加公用方法
     * @param array $data
     * @return bool
     */
    public function insertAdd(array $data = []): bool
    {
        return $this->save($data);
    }

    /**
     * @param int $limit
     * @param array $where
     * @param string $order
     * @param string $field
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function getIndexLimitPage(int $limit = 10, array $where = [], string $order = "id desc", string $field = '*'): array
    {
        return $this->field($field)
            ->where($where)
            ->order($order)
            ->paginate($limit)->toArray();
    }
}